package com.noteit.upload;

import java.io.FileInputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.util.List;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class showImageServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;

    public showImageServlet() {
        super();
    }

	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		String id = "";
		try{	
		    id=request.getParameter("id");
			System.out.println("id is=="+id);
			
			FileInputStream hFile = new FileInputStream(id);
			int i=hFile.available();
			byte data[]=new byte[i];
			hFile.read(data);
			hFile.close();
			response.setContentType("image/*"); //设置返回的文件类型
			OutputStream toClient=response.getOutputStream(); //得到向客户端输出二进制数据的对象
			toClient.write(data);
			toClient.close();
		}catch(Exception e){
			e.printStackTrace();
		} 
	}
	
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		
	}

}
